package com.shu.transientTest;

import java.io.*;

/**
 * @author ssm
 * @version V1.0
 * @description: transient测试
 * @date 2021/7/20 17:20
 */

public class Test {

    public static void main(String[] args) throws IOException, ClassNotFoundException {
        doSerialize();
        doDeSerialize();


//        doSerialize1();
//        doDeSerialize1();
    }

    private static void doDeSerialize1() {

    }

    private static void doSerialize1() {

    }

    private static void doSerialize() throws IOException {

        User user = new User().setName("xx").setAge(1).setPwd("asd");
        ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream("D://temp"));
        outputStream.writeObject(user);
        outputStream.close();
        System.out.println("序列化完毕");
    }

    private static void doDeSerialize() throws IOException, ClassNotFoundException {
        ObjectInputStream os = new ObjectInputStream(new FileInputStream("D://temp"));
        Object object = os.readObject();
        User user = (User) object;
        System.out.println(user.toString());
        System.out.println("反序列化完毕");
    }
}
